package cn.suse.android.logic;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.R.integer;
import android.os.IInterface;

import cn.suse.android.entity.Content;
import cn.suse.android.entity.RecordActive;
import cn.suse.android.entity.User;
import cn.suse.android.entity.Video;
import cn.suse.android.logic.BaseParse;

public class RecordActiveParse extends BaseParse<RecordActive> {

	@Override
	public List<RecordActive> parseData(String content) {
		// TODO Auto-generated method stub
		ArrayList<RecordActive> lists = new ArrayList<RecordActive>(); 
		try {
			JSONArray json = new JSONArray(content);
			JSONArray jsonArray = json.getJSONArray(0);
			for(int i=0;i<jsonArray.length();i++){
				JSONObject object=jsonArray.getJSONObject(i);
				RecordActive record = new RecordActive();
//				record.setPaging(parsePage(jsonArray.getJSONObject("paging")));
				record.setCnum(object.getString("cnum"));
				record.setCtime(object.getString("ctime"));
				record.setRid(object.getString("rid"));
				record.setRnum(object.getString("rnum"));
				record.setSrc(object.getString("src"));
				Content c = new Content();
				JSONObject object2 = object.getJSONObject("main");
				if(object2!=null&&object2.length()>0){
					c.setContent(object2.getString("content"));
					JSONArray jsonArray2 = object2.getJSONArray("videos");
					Video[] videos=null;
					if(jsonArray2!=null&&jsonArray2.length()>0){
						videos = new Video[jsonArray2.length()];
						for(int j=0;i<jsonArray2.length();j++){
							JSONObject jsObject = jsonArray2.getJSONObject(j);
							Video video =new Video();
							video.setImg(jsObject.getString("img"));
							video.setLink(jsObject.getString("link"));
							video.setName(jsObject.getString("name"));
							video.setSwf(jsObject.getString("swf"));
							videos[i] = video;
						}
					}
					c.setVideos(videos);
					JSONArray jsonArray3 = object2.getJSONArray("pics");
					if(jsonArray3!=null&&jsonArray3.length()>0){
						//暂无测试数据
					}
				}
				
				record.setContent(c);
				User user =  null;
				JSONObject userInfo = object.getJSONObject("user");
				if(userInfo!=null){
					user = new User();
					user.setGender(userInfo.getString("gender"));
					user.setLogo50(userInfo.getString("logo50"));
					user.setName(userInfo.getString("name"));
					user.setUid(userInfo.getString("uid"));
				}
				record.setUser(user);
				lists.add(record);
			}
		} catch (JSONException e) {
			e.printStackTrace();
			return null;
		}
		return null;
	}

}
